package com.moody.hibernate.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.moody.hibernate.domain.PriceRaroc;

/**
 * A data access object (DAO) providing persistence and search support for
 * PriceRaroc entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.moody.hibernate.domain.PriceRaroc
 * @author MyEclipse Persistence Tools
 */

public class PriceRarocDAO extends HibernateDaoSupport {
	private static final Logger log = LoggerFactory
			.getLogger(PriceRarocDAO.class);
	// property constants
	public static final String DEBT_NO = "debtNo";
	public static final String CUST_ID = "custId";
	public static final String CUST_NAME = "custName";
	public static final String DEBT_BALACE = "debtBalace";
	public static final String DEBT_CURRENCY = "debtCurrency";
	public static final String EL = "el";
	public static final String EC = "ec";
	public static final String FINANCE_COST = "financeCost";
	public static final String RISK_COST = "riskCost";
	public static final String OPERATE_COST = "operateCost";
	public static final String DEBT_RATE = "debtRate";
	public static final String BUSI_TAX = "busiTax";
	public static final String RISK_PRICE = "riskPrice";
	public static final String RAROC = "raroc";
	public static final String REMARK = "remark";
	public static final String UPDATE_USER_ID = "updateUserId";
	public static final String UPDATE_ORG_ID = "updateOrgId";
	public static final String UPDATE_DATE = "updateDate";

	protected void initDao() {
		// do nothing
	}

	public void save(PriceRaroc transientInstance) {
		log.debug("saving PriceRaroc instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(PriceRaroc persistentInstance) {
		log.debug("deleting PriceRaroc instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public PriceRaroc findById(java.lang.String id) {
		log.debug("getting PriceRaroc instance with id: " + id);
		try {
			PriceRaroc instance = (PriceRaroc) getHibernateTemplate().get(
					"com.moody.hibernate.domain.PriceRaroc", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(PriceRaroc instance) {
		log.debug("finding PriceRaroc instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding PriceRaroc instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from PriceRaroc as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByDebtNo(Object debtNo) {
		return findByProperty(DEBT_NO, debtNo);
	}

	public List findByCustId(Object custId) {
		return findByProperty(CUST_ID, custId);
	}

	public List findByCustName(Object custName) {
		return findByProperty(CUST_NAME, custName);
	}

	public List findByDebtBalace(Object debtBalace) {
		return findByProperty(DEBT_BALACE, debtBalace);
	}

	public List findByDebtCurrency(Object debtCurrency) {
		return findByProperty(DEBT_CURRENCY, debtCurrency);
	}

	public List findByEl(Object el) {
		return findByProperty(EL, el);
	}

	public List findByEc(Object ec) {
		return findByProperty(EC, ec);
	}

	public List findByFinanceCost(Object financeCost) {
		return findByProperty(FINANCE_COST, financeCost);
	}

	public List findByRiskCost(Object riskCost) {
		return findByProperty(RISK_COST, riskCost);
	}

	public List findByOperateCost(Object operateCost) {
		return findByProperty(OPERATE_COST, operateCost);
	}

	public List findByDebtRate(Object debtRate) {
		return findByProperty(DEBT_RATE, debtRate);
	}

	public List findByBusiTax(Object busiTax) {
		return findByProperty(BUSI_TAX, busiTax);
	}

	public List findByRiskPrice(Object riskPrice) {
		return findByProperty(RISK_PRICE, riskPrice);
	}

	public List findByRaroc(Object raroc) {
		return findByProperty(RAROC, raroc);
	}

	public List findByRemark(Object remark) {
		return findByProperty(REMARK, remark);
	}

	public List findByUpdateUserId(Object updateUserId) {
		return findByProperty(UPDATE_USER_ID, updateUserId);
	}

	public List findByUpdateOrgId(Object updateOrgId) {
		return findByProperty(UPDATE_ORG_ID, updateOrgId);
	}

	public List findByUpdateDate(Object updateDate) {
		return findByProperty(UPDATE_DATE, updateDate);
	}

	public List findAll() {
		log.debug("finding all PriceRaroc instances");
		try {
			String queryString = "from PriceRaroc";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public PriceRaroc merge(PriceRaroc detachedInstance) {
		log.debug("merging PriceRaroc instance");
		try {
			PriceRaroc result = (PriceRaroc) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(PriceRaroc instance) {
		log.debug("attaching dirty PriceRaroc instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(PriceRaroc instance) {
		log.debug("attaching clean PriceRaroc instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static PriceRarocDAO getFromApplicationContext(ApplicationContext ctx) {
		return (PriceRarocDAO) ctx.getBean("PriceRarocDAO");
	}

	public void update(PriceRaroc priceRaroc) {
		log.debug("saving CustInfo instance");
		try {
			getHibernateTemplate().update(priceRaroc);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}
}